<template>
    <view>
        <view class="page-bottom-fixed padding-main">
            <view v-if="data_list.length > 0">
                <view v-for="(item, index) in data_list" :key="index" class="item padding-vertical-xl padding-left-xl bg-white spacing-mb flex-row jc-sb align-c border-radius-main">
                    <view class="flex-1 flex-width">
                        <view class="flex-row align-c">
                            <text class="default-address margin-right-sm text-size-xss border-radius-sm">{{item.gender_text}}</text>
                            <text class="address-alias br-main cr-main margin-right-sm text-size-xss border-radius-sm">{{ item.number_code }}</text>
                        </view>
                        <view class="flex-row align-c flex-wrap padding-top-main">
                            <view v-if="item.nickname != ''" class="padding-right-main">{{ item.nickname }}</view>
							<view v-else class="padding-right-main">{{ item.username }}</view>
							<block v-if="item.mobile != '' || item.email != ''">
								<view v-if="item.mobile != ''" class="cr-grey">{{ item.mobile }}</view>
								<view v-else class="cr-grey">{{ item.email }}</view>
							</block>
                        </view>
                    </view>
                    <view class="padding-vertical-main padding-left-main padding-right-xl" @tap="delete_event" :data-value="item.id" :data-index="index">
                        <uni-icons class="spi" type="trash" size="24" color="#666666"></uni-icons>
                    </view>
                </view>
            </view>
            <view v-else>
                <!-- 提示信息 -->
                <component-no-data :propStatus="data_list_loding_status"></component-no-data>
            </view>

            <!-- 结尾 -->
            <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
        </view>

		<!-- 底部悬浮操作栏 -->
		<view class="bottom-action-bar" @tap="people_add_event">
			<uni-icons type="plus" size="20" color="#fff" />
			<text class="btn-text">新增员工</text>
		</view>
    </view>
</template>

<script>
    const app = getApp();
    import componentCommon from '@/components/common/common';
    import componentNoData from '@/components/no-data/no-data';
    import componentBottomLine from '@/components/bottom-line/bottom-line';
	import {system_base_info} from "@/common/js/common/common";
    export default {
        data() {
            return {
                data_list_loding_status: 1,
                data_bottom_line_status: false,
                data_list: [],
                params: null,
				diytheme:null,
				lang_info:null,
            };
        },

        components: {
            componentCommon,
            componentNoData,
            componentBottomLine
        },

        onLoad(params) {
            // 调用公共事件方法
            app.globalData.page_event_onload_handle(params);

            // 设置参数
            this.setData({
                params: params,
            });
        },

        onShow() {
            // 调用公共事件方法
            app.globalData.page_event_onshow_handle();
			
            // 数据初始化
            this.init();
        },

        // 下拉刷新
        onPullDownRefresh() {
            this.init();
        },

        methods: {
			// 加载之前
			init() {
				// 先获取语言基础信息 
				system_base_info()
				.then(data=>{
					this.init_before(data)
					.then(()=>{
						this.init_real();
						
						// 分享菜单处理
						app.globalData.page_share_handle();
					});
				});
			},
			
			// 设置本页参数
			init_before(data){
				var self = this;
				return new Promise((resolve, reject) => {
					self.setData({
						lang_info: data.system_lang_info,
						diytheme: data.diytheme,
					});
					resolve();
				});
			},

            // 初始化
            init_real() {
                var user = app.globalData.get_user_info(this, "init");
                if (user != false) {
                    this.get_data_list();
                } else {
                    this.setData({
                        data_list_loding_status: 0,
                        data_bottom_line_status: false,
                    });
                }
            },

            // 获取数据列表
            get_data_list() {
                this.setData({
                    data_list_loding_status: 1,
                });

                // 获取数据
                uni.request({
                    url: app.globalData.get_request_url('people', 'company', 'classinfo'),
                    method: 'POST',
                    data: {},
                    dataType: 'json',
                    success: (res) => {
                        uni.stopPullDownRefresh();
                        if (res.data.code == 0) {
                            var data = res.data.data;
                            var data_list = data.data || [];
                            if (data_list.length > 0) {
                                // 设置数据
                                this.setData({
                                    data_list: data_list,
                                    data_list_loding_status: 3,
                                    data_bottom_line_status: true,
                                });
                            } else {
                                this.setData({
                                    data_list: [],
                                    data_list_loding_status: 0,
                                    data_bottom_line_status: false,
                                });
                            }
                        } else {
                            this.setData({
                                data_list_loding_status: 0,
                            });
                            if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
                                app.globalData.showToast(res.data.msg);
                            }
                        }
                    },
                    fail: () => {
                        uni.stopPullDownRefresh();
                        this.setData({
                            data_list_loding_status: 2,
                        });
                        app.globalData.showToast(this.$t('common.internet_error_tips'));
                    },
                });
            },

            // 添加地址事件
            people_add_event(e) {
                app.globalData.url_open('/pages/fcc/classinfo/company-peopleadd/company-peopleadd');
            },

            // 删除
            delete_event(e) {
                uni.showModal({
                    title: this.$t('common.warm_tips'),
                    content: this.$t('fengcheche.classinfo.shanchuma'),
                    confirmText: this.$t('common.confirm'),
                    cancelText: this.$t('recommend-list.recommend-list.w9460o'),
                    success: (result) => {
                        if (result.confirm) {
                            // 参数
                            var id = e.currentTarget.dataset.value;
                            var index = e.currentTarget.dataset.index;
            
                            // 加载loding
                            uni.showLoading({
                                title: this.$t('common.processing_in_text'),
                            });
                            uni.request({
                                url: app.globalData.get_request_url('peopledelete', 'company', 'classinfo'),
                                method: 'POST',
                                data: {
                                    id: id,
                                },
                                dataType: 'json',
                                success: (res) => {
                                    uni.hideLoading();
                                    if (res.data.code == 0) {
                                        var temp_data_list = this.data_list;
                                        temp_data_list.splice(index, 1);
                                        var len = temp_data_list.length;
                                        this.setData({
                                            data_list: temp_data_list,
                                            data_list_loding_status: len == 0 ? 0 : 3,
                                            data_bottom_line_status: len == 0 ? false : this.data_bottom_line_status,
                                        });
                                        app.globalData.showToast(res.data.msg, 'success');
                                    } else {
                                        app.globalData.showToast(res.data.msg);
                                    }
                                },
                                fail: () => {
                                    uni.hideLoading();
                                    app.globalData.showToast(this.$t('common.internet_error_tips'));
                                },
                            });
                        }
                    },
                });
            },
        },
    };
</script>
<style>
    @import './company-people.css';
</style>
<style lang="scss">
/* 底部悬浮按钮样式 */
.bottom-action-bar {
  position: fixed;
  bottom: 40rpx;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  max-width: 600rpx;
  height: 80rpx;
  background: #409EFF;
  border-radius: 48rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12rpx;
  box-shadow: 0 8rpx 24rpx rgba(64,158,255,0.3);
  z-index: 10;
  transition: all 0.3s ease;

  .btn-text {
    color: #fff;
    font-size: 32rpx;
    font-weight: 500;
  }

  /* 禁用状态 */
  &.disabled {
    background: #c0c4cc !important;
    box-shadow: 0 8rpx 24rpx rgba(192,196,204,0.3);
    opacity: 0.9;
    
    .btn-text {
      color: #fff;
    }
  }
}
</style>